var util = require('../../utils/util.js');
var ajax = require('../../utils/ajax.js');
var common = require('../../utils/common.js');
var PageBase = require('../../common/PageBase.js');
var app = getApp();

Page(common.extendPage(PageBase, {
    data: {
        dataLoaded: false,
    },

    onLoad(options) {
        this._options = options;

        common.initApp({
            loginSuc: () => {
                this.$loginSuc();
                this._fetch();
            }
        });
    },

    onShareAppMessage: function(res) {
        if (res.from === 'button') {
            // 来自页面内转发按钮
            console.log(res.target)
        }
        return {
            title: this.data.serviceItem.title,
            path: '/pages/serviceDetail/index?id=' + this._options.id,
            success: function(res) {
                // 转发成功
            },
            fail: function(res) {
                // 转发失败
            }
        }
    },

    /**
     * 拉取页面数据
     * @return {[type]} [description]
     */
    _fetch() {
        ajax.G({
            url: '/market/Home/serviceInfo',
            data: {
                service_id: this._options.id
            },
            success: (res) => {
                var {
                    info = {}
                } = res.result;

                this.setData({
                    dataLoaded: true,
                    serviceItem: info
                });
            }
        });
    }

}));